package com.iccaplayer.arduins;

import com.iccaplayer.sequencer.Sequencer;

public class ArduIns {
	final String TAG = "MusicItem";
	
	public static final String[] MIDI_INSTRUMENT = new String[] {
		"-", "Acoustic Grand Piano", "Bright Acoustic Piano",
		"Electric Grand Piano", "Honky-tonk Piano", "Electric Piano 1",
		"Electric Piano 2", "Harpsichord", "Clavinet", "Celesta",
		"Glockenspiel", "Music Box", "Vibraphone", "Marimba", "Xylophone",
		"Tubular Bells", "Dulcimer", "Drawbar Organ", "Percussive Organ",
		"Rock Organ", "Church Organ", "Reed Organ", "Accordion",
		"Harmonica", "Tango Accordion", "Acoustic Guitar (nylon)",
		"Acoustic Guitar (steel)", "Electric Guitar (jazz)",
		"Electric Guitar (clean)", "Electric Guitar (muted)",
		"Overdriven Guitar", "Distortion Guitar", "Guitar harmonics",
		"Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
		"Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1",
		"Synth Bass 2", "Violin", "Viola", "Cello", "Contrabass",
		"Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
		"Timpani", "String Ensemble 1", "String Ensemble 2",
		"Synth Strings 1", "Synth Strings 2", "Choir Aahs", "Voice Oohs",
		"Synth Choir", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
		"Muted Trumpet", "French Horn", "Brass Section", "Synth Brass 1",
		"Synth Brass 2", "Soprano Sax", "Alto Sax", "Tenor Sax",
		"Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
		"Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle",
		"Shakuhachi", "Whistle", "Ocarina", "Lead 1 (square)",
		"Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
		"Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)",
		"Lead 8 (bass + lead)", "Pad 1 (new age)", "Pad 2 (warm)",
		"Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)",
		"Pad 6 (metallic)", "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)",
		"FX 2 (soundtrack)", "FX 3 (crystal)", "FX 4 (atmosphere)",
		"FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)",
		"FX 8 (sci-fi)", "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba",
		"Bag pipe", "Fiddle", "Shanai", "Tinkle Bell", "Agogo",
		"Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom",
		"Synth Drum", "Reverse Cymbal", "Guitar Fret Noise",
		"Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring",
		"Helicopter", "Applause", "Gunshot" };
	
		public final static String[] MIDI_DRUM = new String[] {
			"-", "Acoustic Bass Drum", "Bass Drum1", "Side Stick", "Acoustic Snare", "Hand Clap", 
			"Electric Snare", "Low Floor Tom", "Closed Hi-hat", "High Floor Tom", "Pedal Hi-Hat",
			"Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal1",
			"High Tom", "Ride Cymbal1", "Chinese Cymbal", "Ride Bell", "Tambourine",
			"Splash Cymbal", "Cowbell", "Crash Cymbal2",  "Vibraslap", "Ride Cymbal2",
			"Hi Bongo", "Low Bongo", "Mute Hi Conga", "Open Hi Conga", "Low Conga", 
			"High Timbale", "Low Timbale", "High Agogo", "Low Agogo", "Cabasa",
			"Maracas", "Short Whistle", "Long Whistle", "Short Guiro", "Long Guiro",
			"Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
			"Mute Triangle", "Open Triangle"
		};

	private String insType;
	private String insProg;
	private String drumKeys[] = new String[5];
	private String insName;
	private int nSamples;
	private int deviceNum;
	private boolean isPlaying;
	
	// Null Type
	public ArduIns(String prog, String name){
		this.insType = "";
		this.insProg = prog;
		this.insName = name;
		nSamples = 5;
		isPlaying = false;
	}
	
	// Instrument Type
	public ArduIns(String insType, String prog, String name){
		this.insType = insType;
		this.insProg = prog;
		this.insName = name;	
		nSamples = 5;
		isPlaying = false;
	}
	
	// Drum Kits Type
	public ArduIns(String insType, String drumKey[], String name){
		this.insType = insType;
		this.insProg = insType;
		this.insName = name;	
		nSamples = 5;
		for(int i=0; i<nSamples; i++){
			this.drumKeys[i] = drumKey[i];
		}
		isPlaying = false;
	}
	
	public void setInsType(String type){
		this.insType = type;
	}
	
	public String getInsType(){
		return insType;
	}

	public void setInsProg(String prog){
		insProg = prog;
	}
	
	public String getInsProgString(){	
		return insProg;
	}
	
	public int getInsProgInt(){
		return getInsProgInt(insProg);
	}
	
	public int getInsProgInt(String prog){
		int insNum;		
		insNum = -1;
		
		for(int index=0; index<MIDI_INSTRUMENT.length; index++){
			if(prog.equalsIgnoreCase(MIDI_INSTRUMENT[index])){
				insNum = index - 1;
				break;
			}
		}
		
		return insNum;
	}
	
	public String getInsProgString(int num){
		return MIDI_INSTRUMENT[num];
	}
	
	public void setInsDrumKey(int index, String key){
		drumKeys[index] = key;
	}
	
	public void setInsDrumKey(int index, int key){
		drumKeys[index] = MIDI_DRUM[key-34];
	}
	
	public String getInsDrumKeyString(int index){
		return drumKeys[index];
	}
	
	public int getInsDrumKeyInt(int index){
		int result;
		String key;
		result = -1;
		key = drumKeys[index];
		
		for(int i=1; i<MIDI_DRUM.length; i++){
			if(key.equalsIgnoreCase(MIDI_DRUM[i]))
				result = i + 34;
		}
		
		return result;
	}
	

	
	public void setInsName(String name){
		insName = name;
	}
	
	public String getInsName(){
		return insName;
	}
	
	public void setPlaying(boolean playing){
		isPlaying = playing;
	}
	
	public boolean getPlaying(){
		return isPlaying;
	}	
	
	public void setSamples(int num){
		nSamples = num;
	}
	
	public int getSamples(){
		return nSamples;
	}
	
	public void setDeviceNum(int num){
		deviceNum = num;
	}
	
	public int getDeviceNum(){
		return deviceNum;
	}
}
